/**
 * @class   wosh::SystemLogger
 * @brief   CoreModule which provides access to logs (wosh::LogContext)
 *          and available renderers (wosh::LogHandler).
 *
 * - list info about any (instance of) LogContext
 *
 *
 * - manage log handlers
 * - change settings of a context: change handler (ex: enable stdout)
 *
 *
send log message to someone.. as Message
interazione con systemmonitor
 *
 * @ingroup CoreModules
 ****************************************************************************
 * @version 0.8.013 $Id: SystemLogger.h 2582 2010-05-27 15:25:02Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/*! \page page_core
 * \htmlonly <hr/> \endhtmlonly
 * \section page_core_systemlogger Logging
 *
 * Since WOSH is a complex software, made of thousand of components, a custom logging system
 * has been integrated. It is based on two concepts:
 *
 * [..]
 *

 * A generic log entry has following fields:
 *  - Level - severity of the entry
 *     - \c UNKNOWN [?U]
 *     - \c NONE [?U]
 *     - \c CRITICAL [C!] (red)
 *     - \c WARNING [W^] (orange)
 *     - \c INFO [I-] (blue)
 *     - \c VERBOSE [V_] (gray)
 *     - \c DEBUG [D*] (light-gray)
 *     - \c ALL [?A]
 *  - Context - scope of the entry, usually the component name
 *  - Indentation - low-level components are less indented
 *  - Timestamp - as epoch, milliseconds are usually not included
 *  - Content - the message itself, originally passed as variable-argument-list, rendered as C string
 *
 * Log entries are usually formatted as: \c "LEVEL TIMESTAMP CONTEXT(+indentation) CONTENT"
 *
 *
 * \see wosh::SystemLogger
 * \see wosh::LogContext
 *
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ThreadS;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Core_SystemLogger_H__
 #define __WOSH_Core_SystemLogger_H__

 #include <woshDefs.h>
 #include <core/WoshModule.h>
 #include <core/Containers.h>
 #include <core/ObjectAllocator.h>


namespace wosh {

 #define _SystemLogger_NAME						"SystemLogger"
 #define _SystemLogger_URI						":Logger"

 #define _SystemLogger_METHOD_list_handlers		"list_handlers"

 #define _SystemLogger_METHOD_add_handler		"add_handler"
 #define _SystemLogger_METHOD_remove_handler	"remove_handler"
 #define _SystemLogger_METHOD_link_handler		"link_handler"
 #define _SystemLogger_METHOD_swap_handler		"swap_handler"
 #define _SystemLogger_METHOD_edit_handler		"edit_handler"


class WoshKernel;

class SystemLogger : public WoshModule
 {
	WOSH_MODULE(wosh::SystemLogger)


	protected:
		/**
		 * @brief  Default constructor. Call base constructor and initialize some properties and hosted methods.
		 * @param parent [in] WoshKernel singleton, passed to WoshModule constructor
		 * @note   Called by WoshKernel only. Static getter (gamma singleton) will return NULL until kernel is created.
		 */
		SystemLogger( const WoshKernel* parent = NULL );

		/**
		 * @brief  Call base class implementation and (actually nothing more).
		 * @return result of WoshModule::onKernelInitializing()
		 */
		WRESULT onKernelInitializing();

		friend class wosh::WoshKernel;

	public:
		/**
		 * @brief  Empty Destructor.
		 */
		virtual ~SystemLogger();

//@}
/** @name Public methods
 * @{
 ******************************************************************************/
	public:
		WRESULT installHandler( const std::string& handler_type, const std::string& handler_protocol );
		WRESULT removeHandler( long handler_id );
		WRESULT editHandler( long handler_id, const std::string& handler_protocol );

		WRESULT linkHandler( long handler_id, const std::string& context_name );

//@}
/** @name Internal Mehods
 * @{
 ******************************************************************************/
	private:
		/**
		 * @brief  Access the SystemLogger singleton. Gamma Pattern.
		 *         Static reference is allocated and detroyed by WoshKernel on constructor/destructor respectively
		 * @return pointer to SystemLogger singleton. May be NULL (if kernel has not been allocated yet)
		 */
		static SystemLogger* getInstance();

		int swapHandler_( LogHandler* handler, LogHandler* new_handler = NULL );

//@}
	private:
		Response* mmDoAddHandler( const Request* request );
		Response* mmDoRemoveHandler( const Request* request );
		Response* mmDoLinkHandler( const Request* request );
		Response* mmDoSwapHandler( const Request* request );
		Response* mmDoEditHandler( const Request* request );


}; // class def

}; // namespace wosh

#endif //__WOSH_Core_SystemLogger_H__
